﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OpenWaves.Pagination;
using OpenWaves.Web.Controls;
using OpenWaves.Web.Pagination;

namespace OpenWaves.Web.Tests
{
    public partial class PostBasedPaginationTests : System.Web.UI.Page
    {
        private readonly IEnumerable<int> items = Enumerable.Range(0, 100);

        protected PaginationViewModel<int> Numbers;

        protected int CurrentPageIndex
        {
            get { return ((int?) this.ViewState["CurrentPageIndex"]) ?? 0; }
            set { this.ViewState["CurrentPageIndex"] = value; }
        }

        protected override void OnDataBinding(EventArgs e)
        {
            this.Numbers = this.items.Paginate(10, this.CurrentPageIndex);

            base.OnDataBinding(e);
        }

        protected void OnPageCommand(object sender, PaginationCommandEventArgs e)
        {
            if (e.CommandName == "ChangePage")
            {
                this.CurrentPageIndex = Convert.ToInt32(e.CommandArgument);
                this.DataBind();
            }
        }
    }
}